<template>
    <view class="container">
        <div v-for="item in page.records" class="collection">
            <div class="collection-img" onclick="${url}">
                【{{item.bizTypeName}}】
            </div>
            <div class="collection-name" onclick="${url}">
                <div class="collection-name-up">{{item.bizName}}</div>
            </div>
            <div class="collection-btn">
                <div @click="cancelCollect(item)">取消</div>
            </div>
        </div>

        <uni-load-more :status="status"/>
    </view>
</template>

<script>
import {CollectApi} from '@/api/user/CollectApi'

export default {
    data() {
        return {
			Config: this.$Config,
			Common: this.$Common,
			Auth: this.$Auth,
			ShareUtil: this.$ShareUtil,
			State: this.$store.state,
			Dict: this.$Dict,

            page: {
                total: 0,
                size: 10,
                current: 1,
                pages: 2,
                records: []
            },
            status: 'more',
        }
    },
    onLoad() {
        this.getCollectPage()
    },
    onPullDownRefresh() {
        this.page.current = 1
        this.page.pages = 2
        this.getCollectPage()
    },
    onReachBottom() {
        if (this.page.current !== this.page.pages) {
            this.page.current++
            this.getCollectPage()
        }
    },
    methods: {
        getCollectPage() {
            let that = this
            let param = {
                pageIndex: this.page.current,
                pageSize: this.page.size
            };
            that.status = 'loading'

            CollectApi.getPage(param).then((response) => {
                if (that.page.current === 1) {
                    that.page = response
                } else {
                    that.page.records = that.page.records.concat(response.records)
                }

                that.page.records.forEach(function (item) {
                    item.updateTime = that.Common.timeFormat(item.updateTime, 2)
                })

                if (that.page.current === that.page.pages || that.page.pages === 0) {
                    that.status = 'noMore'
                } else {
                    that.status = 'more'
                }
            })
        },
        cancelCollect(item) {
            let that = this

            uni.showModal({
                title: '提示',
                content: '确定取消收藏吗？',
                success: function (res) {
                    if (res.confirm) {
                        let param = {
                            bizType: item.bizType,
                            bizId: item.bizId,
                            isCollect: false
                        }
                        CollectApi.delete(param).then((response) => {
                            that.getCollectPage()
                        })
                    }
                }
            })
        },
    }
}
</script>

<style scoped>
page{background: #FFF;}
/*关注*/
.collection{ width:94%; display: flex; border-bottom: 1px solid #EEE; margin:0 auto; align-items: center;
                padding:10px 0;}
.collection-img{  }
.collection-name{ flex: 1;}
.collection-name-up{ height: 24px; line-height: 24px; overflow: hidden; text-align: left;}
.collection-name-down{ height:24px; line-height: 24px; overflow: hidden; font-size:12px; color: #999;}
.collection-btn{ width:50px;  }
.collection-btn div{ border:1px solid #EEE; border-radius:5px; display: block; text-align: center; padding:3px 0;
    font-size:12px; }

</style>
